package galaxy.vo;

import java.util.HashMap;

import dviz.tools.ModelRepository;
import dviz.visualSystem.impl.AnimationObject;

import com.jme.light.DirectionalLight;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.SharedMesh;
import com.jme.scene.SharedNode;
import com.jme.scene.shape.*;
import com.jme.scene.state.LightState;
import com.jme.system.DisplaySystem;

// This is the visual object that can be used to visualize Java Objects
// By using @ObjectMap("sphere")
public class SphereVO extends AnimationObject {
	private float colorRed, colorBlue, colorGreen;

	public void setColorRed(float colorRed) {
		this.colorRed = colorRed;
	}

	public void setColorBlue(float colorBlue) {
		this.colorBlue = colorBlue;
	}

	public void setColorGreen(float colorGreen) {
		this.colorGreen = colorGreen;
	}

	public SphereVO(HashMap<String, Object> initVector) {
		super(initVector);

		// Getting the Root Node for this Object to be rendered onto the screen
		Node renderNode = getRenderNode();
//		Node sphere = new SharedNode((Node) ModelRepository.get()
//				.getRepository().get("mars"));
//		sphere.setLocalScale(0.05f);
		// Create a new sphere to be rendered onto screen (JMonkeyEngine API)
		 Sphere sphere = new Sphere("", new Vector3f(), 10, 10, 1);
		 sphere.lockMeshes();
		 sphere.setLocalRotation(new Quaternion(new float[] {
		 (float) Math.PI / 2f, 0, 0 }));
		// sphere.setLocalScale(0.2f);
		// Box sphere = new Box("", new Vector3f(-1, -1, -1),
		// new Vector3f(1, 1, 1));
		// Attach this object onto the render root node
		renderNode.attachChild(sphere);

		if (initVector.get("colorRed") != null)
			colorRed = new Float(initVector.get("colorRed").toString());
		if (initVector.get("colorGreen") != null)
			colorGreen = new Float(initVector.get("colorGreen").toString());
		if (initVector.get("colorBlue") != null)
			colorBlue = new Float(initVector.get("colorBlue").toString());
		LightState lightState = DisplaySystem.getDisplaySystem().getRenderer()
				.createLightState();
		lightState.setEnabled(true);

		DirectionalLight dl = new DirectionalLight();
		dl.setDirection(new Vector3f(1, 1, 1));
		dl.setDiffuse(new ColorRGBA(colorRed, colorGreen, colorBlue, 1));
		dl.setAmbient(new ColorRGBA(colorRed, colorGreen, colorBlue, 1));
		dl.setEnabled(true);

		lightState.attach(dl);

		getRenderNode().setRenderState(lightState);
	}

	public void setX(float x) {
		getRenderNode().getLocalTranslation().setX(x);
	}

	public void setSize(float size) {
		getRenderNode().setLocalScale(size);
	}

	public void setY(float y) {
		getRenderNode().getLocalTranslation().setY(y);
	}

	public void setZ(float z) {
		getRenderNode().getLocalTranslation().setZ(z);
	}

}
